import { defineStore } from "pinia";
import { ref, computed } from "vue";

export const useSpotStore = defineStore("spot", () => {
  const spots = ref([
    {
      id: 1,
      name: "贵港园博园",
      description: "集园林艺术、休闲娱乐于一体的综合性公园",
      image: "/images/spots/yuanboyuan.jpg",
      position: [109.613196, 23.103333],
      distance: 2.5,
      duration: 120,
      rating: 4.8,
      visitCount: 12000,
      openTime: "08:00-22:00",
      isPopular: true,
      isRecommended: true,
    },
    {
      id: 2,
      name: "贵港江滨公园",
      description: "沿江岸线景观带，集休闲、运动、观光于一体",
      image: "/images/spots/jiangbin.jpg",
      position: [109.598235, 23.111646],
      distance: 1.8,
      duration: 90,
      rating: 4.5,
      visitCount: 8000,
      openTime: "全天开放",
      isPopular: true,
      isRecommended: false,
    },
    {
      id: 3,
      name: "贵港文化艺术中心",
      description: "现代化文化艺术展演中心，举办各类文化活动",
      image: "/images/spots/art-center.jpg",
      position: [109.605784, 23.098765],
      distance: 3.2,
      duration: 150,
      rating: 4.6,
      visitCount: 5000,
      openTime: "09:00-21:00",
      isPopular: false,
      isRecommended: true,
    },
    {
      id: 4,
      name: "贵港博物馆",
      description: "展示贵港历史文化的综合性博物馆",
      image: "/images/spots/museum.jpg",
      position: [109.602345, 23.107654],
      distance: 2.1,
      duration: 180,
      rating: 4.7,
      visitCount: 6000,
      openTime: "09:00-17:00",
      isPopular: true,
      isRecommended: true,
    },
    {
      id: 5,
      name: "观音山公园",
      description: "城市地标性山岭公园，视野开阔",
      image: "/images/spots/guanyinshan.jpg",
      position: [109.615678, 23.095432],
      distance: 4.5,
      duration: 120,
      rating: 4.4,
      visitCount: 4000,
      openTime: "06:00-22:00",
      isPopular: false,
      isRecommended: true,
    },
  ]);

  const selectedSpot = ref(null);

  const setSelectedSpot = (spot) => {
    selectedSpot.value = spot;
  };

  const searchSpots = (query) => {
    if (!query) return spots.value;
    const lowercaseQuery = query.toLowerCase();
    return spots.value.filter(
      (spot) =>
        spot.name.toLowerCase().includes(lowercaseQuery) ||
        spot.description.toLowerCase().includes(lowercaseQuery),
    );
  };

  const recommendedRoutes = ref([
    {
      id: 1,
      name: "经典一日游",
      spots: [1, 2, 4],
      duration: "6小时",
      distance: "8.5公里",
    },
    {
      id: 2,
      name: "文化探索线",
      spots: [3, 4, 5],
      duration: "8小时",
      distance: "10公里",
    },
    {
      id: 3,
      name: "休闲半日游",
      spots: [1, 2],
      duration: "4小时",
      distance: "5公里",
    },
  ]);

  return {
    spots,
    selectedSpot,
    setSelectedSpot,
    searchSpots,
    recommendedRoutes,
  };
});
